package com.eco.fanliapp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.dao.AppVersionMapper;
import com.eco.fanliapp.entity.AppVersion;
import com.eco.fanliapp.service.IAppVersionService;
import com.eco.fanliapp.utils.Convert;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * app版本 服务层实现
 * 
 * @author xiaoxx
 * @date 2019-05-15
 */
@Service
public class AppVersionServiceImpl extends ServiceImpl<AppVersionMapper, AppVersion> implements IAppVersionService
{
	@Autowired
	private AppVersionMapper appVersionMapper;

	/**
     * 查询app版本信息
     * 
     * @param id app版本ID
     * @return app版本信息
     */
    @Override
	public AppVersion selectAppVersionById(Integer id)
	{
	    return appVersionMapper.selectAppVersionById(id);
	}
	
	/**
     * 查询app版本列表
     *
     * @return app版本集合
     */
	@Override
	public ServerResponse<PageInfo> selectAppVersionList(Integer currentPage, Integer pageSize){

		PageHelper.startPage(currentPage,pageSize);
		List<AppVersion> appVersions = appVersionMapper.selectAppVersionList(null);
		return ServerResponse.createBySuccess(new PageInfo(appVersions));
	}
	
    /**
     * 新增app版本
     * 
     * @param appVersion app版本信息
     * @return 结果
     */
	@Override
	public int insertAppVersion(AppVersion appVersion)
	{
	    return appVersionMapper.insertAppVersion(appVersion);
	}
	
	/**
     * 修改app版本
     * 
     * @param appVersion app版本信息
     * @return 结果
     */
	@Override
	public int updateAppVersion(AppVersion appVersion)
	{
	    return appVersionMapper.updateAppVersion(appVersion);
	}

	/**
     * 删除app版本对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteAppVersionByIds(String ids)
	{
		return appVersionMapper.deleteAppVersionByIds(Convert.toStrArray(ids));
	}
	
	 /**
     *  新写入数据库记录,app_version
     *
     * @param record
     */
	@Override
    public ServerResponse<List> insert(AppVersion record) {

        int insert = appVersionMapper.insertAppVersion(record);
        if (insert == 1){
            return ServerResponse.createBySuccess("增加成功",appVersionMapper.selectAllAppVersion());
        }
        return ServerResponse.createByErrorMessage("增加不成功");
    }
	
	/**
     *  根据主键来更新符合条件 的数据库记录,app_version
     *
     * @param record
     */
    @Override
    public ServerResponse<List> updateByPrimaryKey(AppVersion record) {

        int update = appVersionMapper.updateAppVersion(record);
        if (update == 1){
            return ServerResponse.createBySuccess("修改成功！",appVersionMapper.selectAllAppVersion());
        }
        return ServerResponse.createByErrorMessage("修改不成功！");
    }

    //app版本查询platform系统：1，安卓；2，IOS
	@Override
	public AppVersion selectAppVersionAllById(String platform) {
		// TODO Auto-generated method stub
		return appVersionMapper.selectAppVersionAllById(platform);
	}

	@Override
	public int deleteAppVersionById(Integer id) {
		return appVersionMapper.deleteAppVersionById(id);
	}

}
